<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<div th:insert="~{common/common::common}"/>
<head>
    <meta charset="UTF-8">
    <title>页面分割转化率</title>
</head>
<body>
    <div th:replace="~{common/leftnavbar::leftnav}"></div>
    <div class="layui-body" id="container" style="weight:700px;height:700px;padding-left:68px;">
        <!--<div style="weight:700px;height:700px;" id="container"></div>-->
    </div>
</body>

<script type="text/javascript" th:inline="javascript">
    var myChart = echarts.init(document.getElementById('container'));

    // 饼图的数据
    var data = [
        { value: 335, name: '产品A' },
        { value: 310, name: '产品B' },
        { value: 234, name: '产品C' },
        { value: 135, name: '产品D' },
        { value: 1548, name: '产品E' }
    ];
    var dataX = [],temp = [],dataY = []
    axios.post('/pscr_data')
        .then(function (res) {
            data = Object.values(res.data);
            console.log(data)
            for (var q=0;q<data[0].position.length;q++){
                dataX.push(data[0].position[q].x);
            }
            for (var i=0;i<data.length;i++){
                for (var j=0;j<data[i].position.length;j++){
                    temp.push(data[i].position[j].y);
                }
            }
            for(var i = 0;i < dataX.length;i++)
                dataY.push({value:temp[i],name:dataX[i]})
            console.log(dataY)
            myChart.setOption(option, true);
        })
        .catch(function (error) {
            console.log(error);
        });
    // 配置图表选项
    var option = {
        title: {
            text: '页面跳转率',
            x: 'center'
        },
        tooltip: {
            trigger: 'item',
            formatter: '{a} <br/>{b}: {c}'
        },
        legend: {
            orient: 'vertical',
            left:'left',
            data: dataX
        },
        series: [
            {
                name: '跳转率比例',
                type: 'pie',
                radius: '45%',
                center: ['50%', '50%'],
                data: dataY,
                itemStyle: {
                    emphasis: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    };

    function accessfunc() {
        if (document.getElementById("access").getAttribute("class")=="layui-nav-item layui-nav-itemed"){
            document.getElementById("access").setAttribute("class", "layui-nav-item");
        } else {
            document.getElementById("access").setAttribute("class", "layui-nav-item layui-nav-itemed");
        }
    }
    function categoryfunc() {
        if (document.getElementById("category").getAttribute("class")=="layui-nav-item layui-nav-itemed"){
            document.getElementById("category").setAttribute("class", "layui-nav-item");
        } else {
            document.getElementById("category").setAttribute("class", "layui-nav-item layui-nav-itemed");
        }
    }
</script>
</html>